<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<script type="text/javascript">
	var tool =[{
		text:"新增",
		iconCls:"icon-add",
		handler:function(){
			$("#d").window({
				title:"新增员工",
				width:"40%",
				height:"50%",
				top:100,
				modal:true
//				href:"addUser"
			});
			$("#d").css("display","block")
		}
	},{
		text:"编辑",
		iconCls:"icon-edit",
		handler:function(){
			var obj  = $("#eta").datagrid("getSelections");
			if(obj == null || obj.length != 1){
				$.messager.alert('提示','选择数据不合法');
			}else{
				$("#e").window({
					title:"编辑员工",
					width:"40%",
				    height:"50%",
				    top:100,
				    modal:true
				});
				editStaff();
				$("#e").css("display","block")
			}
			
			
		}
	},{
		text:"删除",
		iconCls:"icon-remove",
		handler:function(){
			var obj  = $("#eta").datagrid("getSelections");
			if(obj == null || obj.length != 1){
				$.messager.alert('提示','选择数据不合法');
			}else{
				$.post("Employees/dropEmployees",{"staffid":obj[0].staffid},function(data){
					if(data == 200){
						$.messager.alert('提示','删除成功');
						$("#eta").datagrid("reload");
					}else{
						$.messager.alert('提示','删除失败');
					}
				});
			}
			
		}
	}];
</script> 
<script>
	var contentPage = {
        			submitForm:function(){
        				
        				if(!$('#addstaff').form('validate')){
        					$.messager.alert('提示','信息不完整');
        					return ;
    					}else{
    						$.post("Employees/addEmployees",$("#addstaff").serialize(),function(data){
    	    					if(data == 200){
    	    						$.messager.alert('提示','添加成功');
    	    						$("#addstaff").form("reset");
    	    						$("#d").window("close");
    	    						$("#eta").datagrid("reload");
    	    					}else{
    	    						$.messager.alert('提示','添加失败');
    	    					}
    	    				});
    						
    					}
        				
        			},
        			clearForm:function(){
        				$("#addstaff").form("reset");
        			}
        	};
</script>
<script>
	function editStaff(){
    		var obj  = $("#eta").datagrid("getSelections");
    		
    		$("#editstaff").form("load",{
    			staffname:obj[0].staffname,
				staffsex:obj[0].staffsex,
				stafftel:obj[0].stafftel,
				staffpost:obj[0].staffpost,
				staffsal:obj[0].staffsal,
				staffcomm:obj[0].staffcomm,
				staffid:obj[0].staffid
			})
    	}
    	
    	function subform(){
    		$.post("Employees/modifyEmployees",$("#editstaff").serialize(),function(data){
    			
				if(data == 200){
					$.messager.alert('提示','修改成功');
					$("#editstaff").form("reset");
					$("#e").window("close");
					$("#eta").datagrid("reload");
				}else{
					$.messager.alert('提示','修改失败');
				}
			});
    	}
    	
    	function clearform () {
    		$("#editstaff").form("reset");
}

function subAddForm() {
	if(!$('#addstaff').form('validate')) {
		$.messager.alert('提示', '信息不完整');
		return;
	} else {
		$.post("Employees/addEmployees", $("#addstaff").serialize(), function(data) {
			if(data == 200) {
				$.messager.alert('提示', '添加成功');
				$("#addstaff").form("reset");
				$("#d").window("close");
				$("#eta").datagrid("reload");
			} else {
				$.messager.alert('提示', '添加失败');
			}
		});

	}
}
</script>
<table id="eta" class="easyui-datagrid" data-options="url:'Employees/findEmployees',striped:true,fitColumns:true,pagination:true,rownumbers:true,toolbar:tool">
	<thead>
		<th data-options="field:'ck',checkbox:true"></th>
		<th data-options="field:'staffid',hidden:true">ID</th>
		<th data-options="field:'staffname',resizable:true">员工名称</th>
		<th data-options="field:'staffsex',resizable:true">员工性别</th>
		<th data-options="field:'stafftel',resizable:true">员工电话</th>
		<th data-options="field:'staffpost',resizable:true">员工职位</th>
		<th data-options="field:'staffsal',resizable:true">员工工资</th>
		<th data-options="field:'staffcomm',resizable:true">员工提成</th>
	</thead>
	<tbody>
		
	</tbody>
</table>
<div id="d" style="display: none;">
	<form id="addstaff">
		<table border="0" cellspacing="0" cellpadding="0" align="center">
	<tr>
		<td><br />
			<label for="staffname">姓名</label>
		</td>
		<td><br />
			<input type="text" name="staffname" id="staffname" required value="" />
		</td>
	</tr>
	<tr>
		<td><br />
			<label for="staffsex">性别</label>
		</td>
		<td><br />
			<input type="radio" name="staffsex" id="staffsex" value="男" checked />男
			<input type="radio" name="staffsex" id="staffsex" value="女" />女
		</td>
	</tr>
	<tr>
		<td><br />
			<label for="stafftel">电话</label>
		</td>
		<td><br />
			<input type="tel" name="stafftel" id="stafftel" required value="" />
		</td>
	</tr>
	<tr>
		<td><br />
			<label for="staffpost">职位</label>
		</td>
		<td><br />
			<input type="text" name="staffpost" id="staffpost" required value="" />
		</td>
	</tr>
	<tr>
		<td><br />
			<label for="staffsal">薪资</label>
		</td>
		<td><br />
			<input type="number" name="staffsal" id="staffsal" required value="" />
		</td>
	</tr>
	<tr>
		<td><br />
			<label for="staffcomm">提成</label>
		</td>
		<td><br />
			<input type="number" name="staffcomm" id="staffcomm" value="" />
		</td>
	</tr>
	<tr>
		<td colspan="2">
		<br />
			<a href="javascript:void(0)" class="easyui-linkbutton" onclick="subAddForm()" data-options="iconCls:'icon-add'">提交</a>
	        <a href="javascript:void(0)" class="easyui-linkbutton" onclick="clearform()">重置</a>
		</td>
	</tr>
</table>
	</form>
</div>
<div id="e" style="display: none;">
	<form id="editstaff">
	<input type="hidden" name="staffid" id="staffid" required value="" />
		<table border="0" cellspacing="0" cellpadding="0" align="center">
	<tr>
		<td><br />
			<label for="staffname">姓名</label>
		</td>
		<td><br />
			<input type="text" name="staffname" id="staffname" required readonly value="" />
		</td>
	</tr>
	<tr>
		<td><br />
			<label for="staffsex">性别</label>
		</td>
		<td><br />
			<input type="radio" name="staffsex" id="staffsex" value="男" checked disabled />男
			<input type="radio" name="staffsex" id="staffsex" value="女" disabled />女
		</td>
	</tr>
	<tr>
		<td><br />
			<label for="stafftel">电话</label>
		</td>
		<td><br />
			<input type="tel" name="stafftel" id="stafftel" required value="" />
		</td>
	</tr>
	<tr>
		<td><br />
			<label for="staffpost">职位</label>
		</td>
		<td><br />
			<input type="text" name="staffpost" id="staffpost" required value="" />
		</td>
	</tr>
	<tr>
		<td><br />
			<label for="staffsal">薪资</label>
		</td>
		<td><br />
			<input type="number" name="staffsal" id="staffsal" required value="" />
		</td>
	</tr>
	<tr>
		<td><br />
			<label for="staffcomm">提成</label>
		</td>
		<td><br />
			<input type="number" name="staffcomm" id="staffcomm" value="" />
		</td>
	</tr>
	<tr>
		<td colspan="2">
		<br />
			<a href="javascript:void(0)" onclick="subform()" class="easyui-linkbutton" data-options="iconCls:'icon-add'">确认</a>&nbsp;&nbsp;&nbsp;&nbsp;
			<a href="javascript:void(0)" onclick="clearform()" class="easyui-linkbutton" data-options="iconCls:'icon-redo'">重置</a>
		</td>
	</tr>
</table>
	</form>
</div>
